﻿namespace TowerOfHanoi
{
    internal class Program
    { /// <summary>
      /// 用递归算法实现汉诺塔移动过程
      /// </summary>
      /// <param name="args"></param>
        static void Main(string[] args)
        {
            string A = "A"; string B = "B"; string C = "C";   //起始塔A，中转塔B，目标塔C
            Console.WriteLine("请输入汉诺塔层数，层数必须大于0");
            int n = Convert.ToInt32(Console.ReadLine());
            TowerOfHanoi(n, A, B, C);
        }
        static void TowerOfHanoi(int n, string A, string B, string C)
        {
            if (n == 1)//最大的盘从塔A到C
                Console.WriteLine($"移动{n}号盘从{A}移到{C}");
            else
            {
                TowerOfHanoi(n - 1, A, C, B);//将n-1个盘从塔A经过塔C移动到塔B上
                Console.WriteLine($"移动{n}号盘从{A}移到{C}"); //A中最大的盘从塔A移动到塔C
                TowerOfHanoi(n - 1, B, A, C);//将塔B上的n-1个盘移动到塔C上
            }
        }
    }
}